<?php
namespace app\common\model;
use app\common\cache\CacheData;

class Bank extends Base
{
	public function cacheData(){
		$data = $this->select();
		if($data){
			foreach($data as &$value):
				$value=$value->toArray();
			endforeach;
		}
		return $data;
	}
    
	/**
     * 银行缓存
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public static function bankData($id=null){
        $CACHE = CacheData::getInstance('Bank');
        $cacheData = $CACHE -> readCache();
        $cacheData = collection($cacheData)->toArray();
        $banksData = [];
        foreach($cacheData as $cache):
            $banksData[$cache['id']] = $cache;
        endforeach;
        if(!is_null($id)){
            if(isset($banksData[$id])):
                return $banksData[$id];
            else:
                return false;
            endif;
        }else{
            return $banksData;
        }
    }

    public static function bankStatus($status=null){
        $banks = self::bankData();
        $data = [];
        foreach($banks as $bank):
            $data[$bank['status']][$bank['id']]=$bank;
        endforeach;
        if(is_null($status)){
            return $data;
        }else{
            if(isset($data[$status])){
                return $data[$status];
            }else{
                return false;
            }
        }
    }

}
